<?php
class NewsAction extends CommonAction {
    public function index() {
        C('TOKEN_ON',false);
        $news = D('News', 'Admin');
        $newsNav = D('PressNav', 'Admin');
        $map['attr'] = array('like', '%推荐%');
        $recNews = $news->field(array('id', 'title', 'title'=>'ftitle', 'addtime'))
                        ->where($map)
                        ->limit(7)
                        ->order('addtime DESC')
                        ->select();
        $map['attr'] = array('like', '%头条%');
        $topNews = $news->field(array('id', 'title', 'title'=>'ftitle', 'summary'))
                        ->where($map)
                        ->order('addtime DESC')
                        ->find();
        $map['attr'] = array('like', '%置顶%');
        $goodNews = $news->field(array('id', 'title', 'title'=>'ftitle', 'addtime'))
                          ->where($map)
                          ->order('addtime DESC')
                          ->limit(11)
                          ->select();
        $map2['thumbnail'] = array('neq', '');
        $picNews = $news->field(array('id', 'title', 'title'=>'ftitle', 'thumbnail'))
                        ->where($map2)
                        ->limit(6)
                        ->order('addtime DESC')
                        ->select();
        $navs = $newsNav->field(array('id', 'name'))
                        ->where('is_active=1')
                        ->order('sort ASC')
                        ->limit(4)
                        ->select();
        //本月热门
        $now = date('m');
        $monthHot = array();
        $temp = $news->field(array('id', 'title', 'title'=>'ftitle', 'addtime'))
                     ->order('view_count DESC')
                     ->limit(6)
                     ->select();

        foreach($temp as $key=>$value) {
            if(date('m',$value['addtime']) == $now) $monthHot[] = $value;
        }

        $temp2 = $news->Table(array('xinxi_news'=>'xn', 'xinxi_news_commend'=>'xc'))
                      ->field(array('xn.id', 'xn.title',
                                 'xn.title'=>'ftitle',
                                 'COUNT(xn.id)'=>'count',
                                 'xn.addtime'
                             ))
                      ->where('xn.id=xc.nid')
                      ->group('xn.id')
                      ->order('count DESC')
                      ->limit(8)
                      ->select();

        $monthCommend = array();
        foreach($temp2 as $key=>$value) {
            if(date('m', $value['addtime']) == $now) $monthCommend[] = $value;
        }

        //载入新闻导航的文章列表
        foreach($navs as $key=>$value) {
            $myNews = $news->field(array('id', 'title', 'title'=>'ftitle', 'addtime'))
                           ->where('nav='.$value['id'])
                           ->limit(6)
                           ->order('addtime DESC')
                           ->select();
            $value['mynews'] = $myNews;
            $listNews[] = $value;
        }

        //显示广告
        parent::showBanner();

        $this->assign(array(
            'recnews'=>$recNews,
            'topnews'=>$topNews,
            'goodnews'=>$goodNews,
            'picnews'=>$picNews,
            'listnews'=>$listNews,
            'monthhot'=>$monthHot,
            'monthcommend'=>$monthCommend
        ));
        $this->display();
    }
}



?>